package edu.cuit.canary.servlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/8/2 14:43
 */
@WebServlet({"/second.do", "/second.php", "/second.jsp"})
public class SecondServlet extends GenericServlet {
    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        System.out.println("servlet name:" + getServletName());
        //向客户端进行响应
        PrintWriter writer = response.getWriter();
        // 设置响应头(content-type)告诉浏览器响应的内容类型，封装成了方便方便设置
        response.setContentType("text/html; charset=utf-8");
        writer.println("<html>");
        writer.println("<head>");
        writer.println("<title>我的第一个servlet</title>");
        writer.println("<body>");
        writer.print("<p>当前时间:");
        writer.print(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
        writer.println("</p>");
        writer.println("</body>");
        writer.println("</head>");
        writer.println("</html>");
    }
}
